package com.emm.yixun.marketing.service.impl;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebService;

import com.emm.yixun.common.model.dto.*;
import com.emm.yixun.basic.service.*;
import com.emm.yixun.common.model.*;
import com.emm.yixun.common.model.dto.*;
import com.emm.yixun.common.utils.BeanUtil;
import com.emm.yixun.marketing.service.NeedReceiveRefundServiceFacade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.emm.yixun.common.constant.SysConstants;
import com.emm.yixun.common.exception.ResponseCode;
import com.emm.yixun.common.model.HaveReceiveRefund;
import com.emm.yixun.common.model.HaveReceiveRefundInfo;
import com.emm.yixun.common.model.MortgageRecord;
import com.emm.yixun.common.model.NeedReceiveRefund;
import com.emm.yixun.common.model.ReserveArea;
import com.emm.yixun.common.model.Signed;
import com.emm.yixun.common.model.Subscribe;
import com.emm.yixun.common.model.enums.BusinessFlagEnum;
import com.emm.yixun.common.model.enums.BusinessTypeEnum;
import com.emm.yixun.common.model.enums.HousingFundTypeEnum;
import com.emm.yixun.common.model.enums.StatementTypeEnum;
import com.emm.yixun.common.page.Page;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.common.response.ResponseList;
import com.emm.yixun.marketing.service.HaveReceiveRefundServiceFacade;

@Service("haveReceiveRefundServiceFacade")
@WebService(name="com.emm.yixun.marketing.service.HaveReceiveRefundServiceFacade")
public class HaveReceiveRefundServiceFacadeImpl implements HaveReceiveRefundServiceFacade{
	private  final Logger   logger = LoggerFactory.getLogger(this.getClass()); 
	
	@Autowired
	private HaveReceiveRefundService service;
	@Autowired
	private DataPermissionService dataPermissionService;
	@Autowired
	private NeedReceiveRefundService needReceiveRefundService;
	@Autowired
	private MortgageRecordService mortgageRecordService;
	
	@Autowired
	private ReserveAreaService reserveAreaService;
	
	@Autowired
	private SignedService signedService;
	
	@Autowired
	private SubscribeService subscribeService;

	@Autowired
	private PayDepositService payDepositService;

	@Autowired
	private HaveReceiveRefundService haveReceiveRefundService;

	@Autowired
	private CustomerService customerService;

	@Override
	public Response<HaveReceiveRefundDto> save(HaveReceiveRefundDto dto) {
		Response<HaveReceiveRefundDto> response=new Response<HaveReceiveRefundDto>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("保存"));
				return response;
			}
			HaveReceiveRefundDto mDto=service.create(dto);
			if(null==mDto){
				response.fail("80000", "保存数据错误");
				return response;
			}
			response.success(mDto);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("保存数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> updateByPrimaryKey(HaveReceiveRefundDto dto,Boolean selective) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==selective || null==dto || null==dto.getId()){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("更新"));
				return response;
			}
			
			if(selective){
				int count=service.update(dto);
				if(count>0){
					response.success(Integer.valueOf(count));
				}else{
					response.fail("90001", "更新数据失败");
				}
			}else{
				response.fail("90000", "暂未实现,修改参数selective=true即可");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("更新数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Response<Integer> deleteByPrimaryKey(Long id) {
		Response<Integer> response=new Response<Integer>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("删除"));
				return response;
			}
			HaveReceiveRefundDto mDto=new HaveReceiveRefundDto();
			mDto.setId(id);
			int count=service.destroy(mDto);
			if(count>0){
				response.success(Integer.valueOf(count));
			}else{
				response.fail("90001", "删除数据失败");
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("删除数据错误：{}",e);
		}
		return response;
	}
	
    @Override
	public Response<HaveReceiveRefund> findById(Long id) {
		Response<HaveReceiveRefund> response=new Response<HaveReceiveRefund>();
		try {
			if(null==id){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("主键查询"));
				return response;
			}
			HaveReceiveRefund entity=service.selectById(id);
			if(null==entity){
				response.fail("90001", "主键查询数据失败");
			}else{
				response.success(entity);;
			}
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("主键查询数据错误：{}",e);
		}
		return response;
	}
    
    @Override
   	public Response<HaveReceiveRefundInfo> findInfoById(Long id) {
   		Response<HaveReceiveRefundInfo> response=new Response<HaveReceiveRefundInfo>();
   		try {
   			if(null==id){
   				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("主键查询"));
   				return response;
   			}
   			HaveReceiveRefundInfo entity=service.selectInfoById(id);
   			if(null==entity){
   				response.fail("90001", "主键查询数据失败");
   			}else{
   				response.success(entity);;
   			}
   		} catch (Exception e) {
   			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
   			logger.error("主键查询数据错误：{}",e);
   		}
   		return response;
   	}

	@Override
	public ResponseList<HaveReceiveRefund> findByDto(HaveReceiveRefundDto dto) {
		ResponseList<HaveReceiveRefund> response=new ResponseList<HaveReceiveRefund>();
		try {
			if(null==dto){
				response.fail(ResponseCode.PARAM_INVALID.getCode(), ResponseCode.PARAM_INVALID.formatMessage("查询"));
				return response;
			}
			List<HaveReceiveRefund> list=service.selectListByDto(dto);
			if(null==list){
				response.fail(ResponseCode.NO_DATA_FOUND.getCode(), ResponseCode.NO_DATA_FOUND.formatMessage("查询"));
				return response;
			}
			response.success(list);
		} catch (Exception e) {
			response.fail(ResponseCode.SYSTEM_EXCEPTION.getCode(), ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Page<HaveReceiveRefund> findPageByDto(HaveReceiveRefundDto dto, Integer begin,Integer row) {
		Page<HaveReceiveRefund> response=new Page<HaveReceiveRefund>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			Page<HaveReceiveRefund> page = service.getPageModel(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			response=page;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Page<HaveReceiveRefundInfo> findPageByDtoReport(HaveReceiveRefundInfoDto dto, Integer begin,Integer row) {
		Page<HaveReceiveRefundInfo> response=new Page<>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			Page<HaveReceiveRefundInfo> page = service.getPageModelReport(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			response=page;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}
	
	@Override
	public Page<HaveReceiveRefundInfo> findPageByDtoInfo(HaveReceiveRefundInfoDto dto, Integer begin,Integer row) {
		Page<HaveReceiveRefundInfo> response=new Page<HaveReceiveRefundInfo>();
		try {
			if(null==dto || null==begin || null==row){
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			String sbsql =  " and t.receivables_type IN (";
			if(!StringUtils.isEmpty(dto.getReceivablesType())){
				String[] receivablesType = dto.getReceivablesType().split(",");
				for (int i = 0; i < receivablesType.length; i++) {
					sbsql += receivablesType[i];
					if (i != receivablesType.length - 1) {
						sbsql += ",";
					}
				}
				sbsql = sbsql + ")";
				dto.setReceivablesType(sbsql);
			}
			
			//数据权限
			if(SysConstants.openDataPermission){
				String dataPermission = dataPermissionService.dataPermissionCondition(dto.getPermissionUserId(), dto.getResourcesCode(), null, null);
				String [] dataPermissionArr = dataPermission.split(":");
				dto.setDataPermission(dataPermissionArr[1]);
			}
			
			Page<HaveReceiveRefundInfo> page = service.getPageModelInfo(dto, begin, row);
			if(null==page.getRows()){
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}

			List<HaveReceiveRefundInfo> list = page.getRows();
			for (int i = 0; i < list.size(); i++) {
				HaveReceiveRefundInfo info = (HaveReceiveRefundInfo) list.get(i);
				if (info.getRelationId() != null) {
					long relationId = info.getRelationId();
					// 当业务类型是面积补差时
					if (info.getReceivablesType().equals(BusinessTypeEnum.AREA.getNo())) {
						ReserveArea reserveArea = reserveAreaService.selectById(info.getRelationId());
						if (reserveArea != null) {
							relationId = reserveArea.getSignedId();
						}
					}
					// 查询签约信息
					if(info.getReceivablesType().equals(BusinessTypeEnum.SIGNED.getNo())){
						Signed signed = signedService.selectById(relationId);
						if (signed != null) {
							if(signed.getCalculateArea() != null){
								info.setCalculatArea(signed.getCalculateArea().toString());
							}
							info.setPrice(signed.getSignPrice());
							info.setTotalPrice(signed.getSignAmount());
						}
					}
					// 查询认购信息
					if(info.getReceivablesType().equals(BusinessTypeEnum.SUBSCRIBE.getNo())){
						Subscribe subscribe = subscribeService.selectById(relationId);
						if (subscribe != null) {
							if(subscribe.getCalculateArea() != null){
								info.setCalculatArea(subscribe.getCalculateArea().toString());
							}
							info.setPrice(subscribe.getSubscribePrice());
							info.setTotalPrice(subscribe.getSubscribeAmount());
						}
					}

				}
				if (!StringUtils.isEmpty(info.getHousingFundType())) {
					// 房款类型
					info.setRelationType(HousingFundTypeEnum.getByNo(info.getHousingFundType()).getDes());
				}
				if (!StringUtils.isEmpty(info.getBusinessFlag())) {
					// 业务标志
					info.setBusinessType(BusinessFlagEnum.getByNo(info.getBusinessFlag()).getDes());
				}
				// 结算日期 + 结算人员 + 结算方式
				String statement = "";
				if (info.getStatementDate() != null) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					statement = sdf.format(info.getStatementDate());
				}
				if (!StringUtils.isEmpty(info.getStatement_name())) {
					statement = statement + "/" + info.getStatement_name();
				}
				if (info.getStatementType() != null) {
					info.setPaymentMethod_name(StatementTypeEnum.getByNo(info.getStatementType() + "")
							.getDes());
					statement = statement + "/"
							+ StatementTypeEnum.getByNo(info.getStatementType() + "").getDes();
				}
				info.setStatement(statement);

				// 票据信息，当新票据号不为空时取新票据号
				if (!StringUtils.isEmpty(info.getNewBillCode())) {
					info.setBillCode(info.getNewBillCode());
				}

			}
			response=page;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}",e);
		}
		return response;
	}

	@Override
	public Double haveReceiveAmount(HaveReceiveRefundDto dto) {
		double receivedAmount = 0;
		try {
			receivedAmount = service.haveReceiveAmount(dto);
			
		} catch (Exception e) {
			logger.error("获取已收金额失败",e);
		}
		return receivedAmount;
	}

	@Override
	public Response<BigDecimal> findHaveAmount(Long needId) {
		Response<BigDecimal> response = new Response<BigDecimal>();
		try {
			BigDecimal big = new BigDecimal("0");
			HaveReceiveRefundDto entity = new HaveReceiveRefundDto();
			entity.setReceivablesId(needId);
			entity.setTransferStatus("0");
			entity.setDocType("0");
			List<HaveReceiveRefund> list = service.selectListByDto(entity);
			for (HaveReceiveRefund refund : list) {
				if(!refund.getBusinessFlag().equalsIgnoreCase(BusinessFlagEnum.BUSINESSFLAG_11.getNo())){
					big=big.add(refund.getRealAmount());
				}
				
			}
			response.setEntity(big);
			response.setSuccess(true);
		} catch (Exception e) {
			logger.error("findHaveAmount error: ", e);
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public Response<Integer> deleteByDto(HaveReceiveRefundDto dto) {
		Response<Integer> response = new Response<Integer>();
		int count=service.destroy(dto);
		if(count>0){
			response.success(Integer.valueOf(count));
		}else{
			response.fail("90001", "删除数据失败");
		}
		return response;
	}
	
	@Override
	public boolean addRefund(HaveReceiveRefundDto entity, long id, BigDecimal counterFee, BigDecimal realAmount,
			String needOrHave) {
		boolean flag = false;
		try {
			if (counterFee.compareTo(new BigDecimal("0")) >= 1) {
				// 当退款金额大于0时，增加一条保存手续费
				entity.setRealAmount(counterFee); // 手续费
				entity.setBusinessFlag("16"); // 退款手续费
				HaveReceiveRefundDto response = service.create(entity);
				if (response == null) {
					return flag;
				}
			}
			entity.setRealAmount(realAmount); // 实退金额
			if (entity.getReceivablesType().equals(BusinessTypeEnum.DEPOSIT.getNo())) {
				entity.setBusinessFlag("4"); // 退认筹
			} else if (entity.getReceivablesType().equals(BusinessTypeEnum.SUBSCRIBE.getNo())) {
				entity.setBusinessFlag("8"); // 退认购
			} else if (entity.getReceivablesType().equals(BusinessTypeEnum.SIGNED.getNo())) {
				entity.setBusinessFlag("14"); // 退签约
			} else if (entity.getReceivablesType().equals(BusinessTypeEnum.AREA.getNo())) {
				entity.setBusinessFlag("15"); // 补差款
			}
			HaveReceiveRefundDto response = service.create(entity);
			if (response != null) {
				// 将原已收款/带退款信息修改为已删除
				int res = 0;
				if ("have".equals(needOrHave)) {
					//已收款退款操作
					//1.判断退款金额，如果全部退，则删掉已收记录,并设置已收款金额为0，如果部分退，则减少发生金额
					HaveReceiveRefund haveReceiveRefund = service.selectById(id);
					if (haveReceiveRefund != null) {
						BigDecimal oldRealAmount = haveReceiveRefund.getRealAmount();
						if (oldRealAmount.compareTo(realAmount) > 0) {
							HaveReceiveRefundDto edit = new HaveReceiveRefundDto();
							edit.setId(id);
							//原已收款金额-退款金额
							edit.setRealAmount(oldRealAmount.subtract(realAmount));
							res = service.update(edit);
						} else if (oldRealAmount.compareTo(realAmount) <= 0) {
							HaveReceiveRefundDto edit = new HaveReceiveRefundDto();
							edit.setId(id);
							edit.setRealAmount(BigDecimal.ZERO);
							edit.setDelFlag("1");
							res = service.update(edit);
						}

						//发生退款，修改应收款状态
						Long needId = haveReceiveRefund.getReceivablesId();
						//未收金额
						NeedReceiveRefund nrResponse = needReceiveRefundService.selectById(needId);
						//已收金额
						Response<BigDecimal> hraResponse = findHaveAmount(needId);
						if (nrResponse != null
								&& nrResponse.getTotalReceivablesAmount().compareTo(hraResponse.getEntity()) > 0) {
							//更新应收款记录为未删除
							NeedReceiveRefundDto edit = new NeedReceiveRefundDto();
							edit.setId(nrResponse.getId());
							edit.setDelFlag("0");
							edit.setStatus("1");
							needReceiveRefundService.update(edit);
						}
						//更新按揭收款状态
						if (nrResponse != null && hraResponse.isSuccess()) {
							//查询应收款对应的按揭记录
							MortgageRecordDto queryEntity = new MortgageRecordDto();
							queryEntity.setNeedId(needId);
							List<MortgageRecord> rlMrList = mortgageRecordService.selectListByDto(queryEntity);
							//当存在按揭记录才去更新
							if (rlMrList != null) {
								//应收金额
								BigDecimal totalReceivablesAmount = nrResponse.getTotalReceivablesAmount();
								//已收金额
								BigDecimal haveAmount = hraResponse.getEntity();

								if (haveAmount.compareTo(BigDecimal.ZERO) <= 0) {
									//当已收款金额小于等于0时更新按揭收款状态为未收款
									for (MortgageRecord mortgageRecord : rlMrList) {
										MortgageRecordDto updateDto = new MortgageRecordDto();
										updateDto.setId(mortgageRecord.getId());
										updateDto.setMortgageReceivedStatus("0");//已收款
										mortgageRecordService.update(updateDto);
									}
								} else if (haveAmount.compareTo(BigDecimal.ZERO) > 0
										&& haveAmount.compareTo(totalReceivablesAmount) < 0) {
									//当已收款金额大于0而且小于应收款金额时更新按揭收款状态为部分付款
									for (MortgageRecord mortgageRecord : rlMrList) {
										MortgageRecordDto updateDto = new MortgageRecordDto();
										updateDto.setId(mortgageRecord.getId());
										updateDto.setMortgageReceivedStatus("1");//已收款
										mortgageRecordService.update(updateDto);
									}
								} else if (haveAmount.compareTo(totalReceivablesAmount) >= 0) {
									//当已收款金额大于等于应收款金额时更新按揭收款状态为已付款
									for (MortgageRecord mortgageRecord : rlMrList) {
										MortgageRecordDto updateDto = new MortgageRecordDto();
										updateDto.setId(mortgageRecord.getId());
										updateDto.setMortgageReceivedStatus("2");//已收款
										mortgageRecordService.update(updateDto);
									}
								}
							}
						}
					}
				} else if ("need".equals(needOrHave)) {
					//待退款退款操作 (ym)  
					HaveReceiveRefundDto queryHaveReceiveRefundDto = new HaveReceiveRefundDto();
					queryHaveReceiveRefundDto.setReceivablesId(id);
					queryHaveReceiveRefundDto.setTransferStatus("0");
					queryHaveReceiveRefundDto.setDocType("1");
					Double havaReceiveAmount = haveReceiveAmount(queryHaveReceiveRefundDto);
					if (null == havaReceiveAmount)
						havaReceiveAmount = Double.valueOf("0");
					//Response<BigDecimal> hraResponse=haveReceiveRefundServiceFacade.findHaveAmount(id);
					NeedReceiveRefund resp = needReceiveRefundService.selectById(id);
					if (resp != null) {
						BigDecimal hraAmount = new BigDecimal(havaReceiveAmount);
						BigDecimal totalReceivablesAmount = resp.getTotalReceivablesAmount();
						//已退金额- 待退金额，当大于等于0相当于退完了，待退金额将标示为已删除，待退列表不显示
						if (hraAmount.compareTo(totalReceivablesAmount) >= 0) {
							NeedReceiveRefundDto edit = new NeedReceiveRefundDto();
							edit.setId(id);
							edit.setDelFlag("1");
							res = needReceiveRefundService.update(edit);
						}
					}

				}
				if (res > 0) {
					flag = true;
				}
			} 
		} catch (Exception e) {
			logger.error("addRefund error: ", e);
		}
		return flag;
	}
	
	@Override
	public Response<BigDecimal> findHaveAmountByDto(HaveReceiveRefundDto entity) {
		Response<BigDecimal> response = new Response<BigDecimal>();
		try {
			BigDecimal big = new BigDecimal("0");
			List<HaveReceiveRefund> list = service.selectListByDto(entity);
			for (HaveReceiveRefund refund : list) {
				if(!refund.getBusinessFlag().equalsIgnoreCase(BusinessFlagEnum.BUSINESSFLAG_11.getNo())){
					big = big.add(refund.getRealAmount());
				}
			}
			response.setEntity(big);
			response.setSuccess(true);
		} catch (Exception e) {
			logger.error("findHaveAmountByDto error: ", e);
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public Response<BigDecimal> findSubscribeHaveAmount(Long subId) {
		Response<BigDecimal> response= new Response<BigDecimal>();
		response.setEntity(service.findSubscribeHaveAmount(subId));
		response.setSuccess(true);
		return response;
	}

	@Override
	public Page<HaveReceiveRefundInfo> findHaveReceivePageInfoByDto(HaveReceiveRefundInfo dto, Integer begin, Integer row) {
		Page<HaveReceiveRefundInfo> response = new Page<HaveReceiveRefundInfo>();
		try {
			if (null == dto || null == begin || null == row) {
				response.setSuccess(false);
				response.setErrorMsg("参数不合法");
				return response;
			}
			Page<HaveReceiveRefundInfo> page = service.findHaveReceivePageInfoByDto(dto, begin, row);
			if (null == page.getRows()) {
				response.setSuccess(false);
				response.setErrorMsg("分页数据不存在");
				return response;
			}
			response = page;
			response.setSuccess(true);
		} catch (Exception e) {
			response.setSuccess(false);
			response.setErrorMsg(ResponseCode.SYSTEM_EXCEPTION.getMessageTemplate());
			logger.error("查询分页数据错误：{}", e);
		}
		return response;
	}

	@Override
	public ResponseList<HaveReceiveRefundInfo> findHaveReceiveInfoByDto(HaveReceiveRefundInfo dto) {
		ResponseList<HaveReceiveRefundInfo> responseList = new ResponseList<HaveReceiveRefundInfo>();
		try {
			List<HaveReceiveRefundInfo> haveReceiveRefundList = service.findHaveReceiveInfoByDto(dto);
			responseList.setEntity(haveReceiveRefundList);
			responseList.setSuccess(true);
		} catch (Exception e) {
			responseList.setSuccess(false);
			logger.error("querySignedDtoExport error: ", e);
		}
		return responseList;
	}

//	@Override
//	public Page<HaveReceiveRefundInfo> findHaveReceivePageInfoByDto(HaveReceiveRefundInfoDto dto, Integer begin, Integer row) {
//
//	}
//
//	@Override
//	public ResponseList<HaveReceiveRefundInfo> findHaveReceiveInfoByDto(HaveReceiveRefundInfoDto dto) {
//
//	}
	public void updateHaveReceiveCustomerInfo(){
		Map<String,PayDepositDto> payDepositMap = new HashMap<String,PayDepositDto>();
		try{
			//查询出所有认筹基础数据
			List<PayDeposit> payDepositLs = payDepositService.selectListByDto(new PayDepositDto());
			for(PayDeposit pd: payDepositLs){
				if(payDepositMap.get(pd.getPayerName()) == null){
					String cusName = pd.getPayerName();
					Long cusId = null;
					//分隔的名称
					String[]  cusNames = cusName.split(",");
					for (String cname:cusNames){
						CustomerDto cdto = new CustomerDto();
						cdto.setCustomerName(cname);
						List<Customer> cusLs = customerService.selectListByDto(cdto);
						if(cusLs != null && cusLs.size()>0 ){
							cusId = cusLs.get(0).getId();
							break;
						}
					}

					if(cusId==null){
						continue;
					}


					pd.setCustomerId(cusId);
					PayDepositDto pddto = new PayDepositDto();
					BeanUtil.convert2T(pddto,pd);
					payDepositService.update(pddto);
					payDepositMap.put(pd.getPayerName(),pddto);
				}else{
					PayDepositDto tem = payDepositMap.get(pd.getPayerName());
					pd.setCustomerId(tem.getCustomerId());
					PayDepositDto pddto = new PayDepositDto();
					BeanUtil.convert2T(pddto,pd);
					payDepositService.update(pddto);
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}

		try{
			//查询出所有认筹应收数据
		}catch (Exception e){
			e.printStackTrace();
		}

		try{
			//查询出所有认筹实收数据
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
